package com.nervenets.web.hibernate.dao;

import com.nervenets.web.hibernate.domain.statistics.StatisticsOfUser;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

@Repository
public interface StatisticsOfUserDao extends JpaRepository<StatisticsOfUser, Long>, JpaSpecificationExecutor<StatisticsOfUser> {
    StatisticsOfUser findByCreateTime(int createTime);

    @Modifying
    @Transactional
    @Query(value = "update `statistics_of_user` set v = v + 1, newly = newly + ?1, active = active + ?2, buy = buy + ?3, re_buy = re_buy + ?4 where ct in (0,?5)", nativeQuery = true)
    void updateCount(int newly, int active, int buy, int reBuy, int time);
}
